package com.example.luke.shengdangxiaoattendance.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.example.luke.shengdangxiaoattendance.Adapter.ClassSelectionAdapter;
import com.example.luke.shengdangxiaoattendance.Model.ClassBean;
import com.example.luke.shengdangxiaoattendance.R;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by luke on 18/07/2017.
 */

public class ClassSelectionDialog extends Dialog {

   public interface  ClassSelectionListener{
         void selectedClass(String className);

    }
    ClassSelectionListener classSelectionListener;

    @InjectView(R.id.containerList)ListView containerList;
  private   ArrayList<ClassBean>classBeanArrayList;

   public ClassSelectionDialog(Context context){
        super(context);
    }

    public void setClassSelectionListener(ClassSelectionListener classSelectionListener) {
        this.classSelectionListener = classSelectionListener;
    }

    public void setClassBeanArrayList(ArrayList<ClassBean> classBeanArrayList) {
        this.classBeanArrayList = classBeanArrayList;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.class_selection_list);

        initView();

    }


     private void initView(){
            ButterKnife.inject(this);
         ClassSelectionAdapter classSelectionAdapter=new ClassSelectionAdapter(getContext(),this.classBeanArrayList);
         containerList.setAdapter(classSelectionAdapter);
         containerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 dismiss();
                 if (classSelectionListener!=null)
                     classSelectionListener.selectedClass(classBeanArrayList.get(position).className);
             }
         });
     }
}

